package com.customer.controller.customer;

import com.alibaba.fastjson.JSON;
import com.customer.service.customer.CustomerService;
import com.customer.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 2 * @Author: xy
 * 3 * @Date: 2021/10/14 下午 6:59:39
 */
@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;


    @ResponseBody
    @RequestMapping("/sendSms")
    public String sendSms(@RequestParam String phoneNumber) {
//        发送验证码
        // 使用短信服务发送验证码，并返回验证码
        String code = customerService.smsSending(phoneNumber);
        // 进行验证码缓存 返回项目中统一定义的响应结果
        ResponseData responseData = customerService.cacheVerificationCode(phoneNumber, code);
        return JSON.toJSONString(responseData);
    }

    @ResponseBody
    @RequestMapping("/login")
    public String login(String phoneNumber, String code) {
        ResponseData responseData = customerService.login(phoneNumber, code);
        return JSON.toJSONString(responseData);
    }

}
